/*------------------------------------------------------*/
/*                                                      */
/* Copyright (C)	sky-mobi.com                        */
/* All rights reserved                                  */
/*                                                      */
/* Author   tristan.yang                                */
/*                                                      */
/* History  2011-5-10 created                           */
/*                                                      */
/*------------------------------------------------------*/

#ifndef __SOURCE_H__
#define __SOURCE_H__

#include "database.h"

class CStreamPackage;
typedef std::vector<CStreamPackage*>	SendPackType;

class RT_API_EXPORT CSource 
: public CRtTimerWrapperSink
, public CRtReferenceControlSingleThread
{
public: 
	CSource(const strKeyId& infoKey);
	virtual ~CSource();

	enum{
		STU_NON_Initialize = 0,
		STU_Initializing = 1,
		STU_Initialized = 2,
		STU_STORE_MEMORY = 10,
		STU_STORE_DISK = 11,
		STU_CONNECTING = 20,
		STU_CONNECTED = 21,
		STU_DISCONNECT = 22
	};
	
	virtual void OnRecvData(CRtMessageBlock& datablock);
	virtual LPSTR GetData(s_DataPos& sposBegin, DWORD& dwSize, BOOL& bEnd, BOOL bIFrame = FALSE);
	virtual LPSTR GetHeadParam(DWORD& dwSize);

	//add for mg support
	virtual RtResult GetStreamData(void* pObj, const st_PackInfo& refInfo,
									SendPackType& refVec){return RT_OK;}
#ifdef _USE_AV_PUSH_MODE
	virtual void Regist(void* pObj, const st_PackInfo& refInfo){}
	virtual void UnRegist(void* pObj, const st_PackInfo& refInfo){}
#endif //_USE_AV_PUSH_MODE
	virtual void GetStreamInfo(vecStreamInfo& refVec){}
	//end add
	
	virtual void SetSize(DWORD dwSize);
	virtual DWORD GetTotalLen();
	virtual void SetStatus(DWORD dwStu);

	virtual void SetStoreFlag(DWORD dwFlag){m_dwStoreType |= dwFlag;}
	virtual void ClearStoreFlag(DWORD dwFlag){m_dwStoreType &= ~dwFlag;}
	virtual DWORD GetStoreFlag(){return m_dwStoreType;}
	virtual DWORD GetLiveTick(){return m_dwLiveTick;}

	virtual const strKeyId& GetKey(){return m_strKey;}
protected: // from CRtTimerWrapperSink
	virtual void OnTimer(CRtTimerWrapper* aID);
	
protected:
	strKeyId	m_strKey;
	DWORD		m_dwStoreType;
	LONGLONG	m_dwLiveTick;
};

#endif//__SOURCE_H__
